import {Observable, of} from 'rxjs';
import {HttpClient, HttpParams} from '@angular/common/http';
import {Inject, Injectable} from '@angular/core';
import {catchError, tap} from 'rxjs/internal/operators';
import {APP_CONFIG} from '../config/app.config';

@Injectable()
export class LoginService {
  private baseUrl: string;

  private alreadyLogin = false;

  constructor(@Inject(APP_CONFIG) appConfig, private http: HttpClient) {
    // this.baseUrl = 'https://admin.aawashcar.com/';
    this.baseUrl = appConfig.endpoints.base;
  }


  isLogin(): Observable<boolean> {
    return of(this.alreadyLogin);
  }
  login(username: string, password: string): Observable<any> {
    if (username === 'admin123' && password === 'abcd1234') {
      this.alreadyLogin = true;
      return of(true);
    }
    this.alreadyLogin = false;
    return of(false);
    // const params = new HttpParams()
    //   .set('username', username)
    //   .set('passport', password);
    // return this.http.post<any>(this.baseUrl + 'tokens/', null, { params }).pipe(
    //   tap(() => console.log('login successfully!'), () => console.log('login error!'))
    // );
  }
}
